{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10a51391",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Author : Zhichao\n",
    "# date : week07\n",
    "\n",
    "# 回顾\n",
    "\n",
    "names_str = \"Alex,Marry,Jack\"\n",
    "names_list = [\"Alex\",\"Marry\",\"Jcak\"]\n",
    "\n",
    "# print(names_str[0:4]) # 字符串，我无法确定名字长度？ 用切片的复杂操作\n",
    "# print(names_list[0]) # 用index索引的操作\n",
    "\n",
    "\n",
    "# 本周重点： list的方法\n",
    "# 思考：对于一个序列数据，我们可以做什么操作？\n",
    "# 1.取值：切片\n",
    "# 2.增加/新增数据，stu_网新1班 =[...]\n",
    "\n",
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "# 2.1 append() 圆括号的内容是 对象（比较大的一个范围，python中一切皆是对象）\n",
    "#     append() 新增在末尾\n",
    "names.append(\"zhichao\")\n",
    "names.append(\"youge\")\n",
    "print(names)\n",
    "\n",
    "# 2.2 insert() 指定位置新增数据\n",
    "names.insert(2,\"zhichao\")\n",
    "print(names)\n",
    "\n",
    "# 3.删除\n",
    "# 3.1 remove() 的操作应该先做查询，判断元素value是否存在？\n",
    "names.remove(\"youge\")\n",
    "print(names)\n",
    "\n",
    "# * 先做查询： seq的一般方法（通用方法）\n",
    "# print(\"lihua\" in names) # False/True\n",
    "# username = input(\"names:\")\n",
    "# if username in names:\n",
    "#     # 删除该用户\n",
    "#     names.remove(username)\n",
    "# else:\n",
    "#     names.append(username)\n",
    "# print(names)\n",
    "# names.remove(\"lihua\")\n",
    "# print(names)\n",
    "\n",
    "# 3.2 pop() 在使用pop()之前，要先了解list的长度？清楚删除的索引位置?\n",
    "# 要先了解list的长度？seq 一般方法 len()\n",
    "print(len(names))\n",
    "print(names)\n",
    "names.pop(2)\n",
    "print(names)\n",
    "# 清楚删除的索引位置?\n",
    "# print(names.index(\"Jan\"))\n",
    "# 案例： 删除一些具有特征的索引值\n",
    "# for i in range(0,len(names)-1,2):\n",
    "#     names.pop(i)\n",
    "# print(names)\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
